﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model._Admin;
using nERP.Model;

namespace nERP.ViewModel._Admin.DicDefVMs
{
    public partial class DicDefListVM : BasePagedListVM<DicDef_View, DicDefSearcher>
    {
        
        protected override IEnumerable<IGridColumn<DicDef_View>> InitGridHeader()
        {
            return new List<GridColumn<DicDef_View>>{
                
                this.MakeGridHeader(x => x.DicDef_DicName).SetTitle(@Localizer["Page.字典集名"].Value),
                this.MakeGridHeader(x => x.DicDef_DicField_DicDef_ID_Count).SetTitle(@Localizer["Page.数量"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<DicDef_View> GetSearchQuery()
        {
            var query = DC.Set<DicDef>()
                
                .CheckContain(Searcher.DicName, x=>x.DicName)
                .Select(x => new DicDef_View
                {
				    ID = x.ID,
                    
                    DicDef_DicName = x.DicName,
                    DicDef_DicField_DicDef_ID_Count = x.DicField_DicDef.Count(),
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class DicDef_View: DicDef
    {
        
        public string DicDef_DicName { get; set; }
        public int? DicDef_DicField_DicDef_ID_Count { get; set; }

    }

}